<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
    <style>
        #timeline-form img {
            max-height: 300px;
            max-width: 800px;
        }
    </style>
	<div class="page-header">
		<h1><?=isset($timeline) ? '编辑德育动态' : '发布德育动态'?></h1>
	</div>
	<div class="col-xs-12">
		<form class="form-horizontal" id="timeline-form">
            <input type="hidden" name="id" value="<?=isset($timeline) ? $timeline['id'] : 0?>" />
            <input type="hidden" name="cover" value="<?=isset($timeline) ? $timeline['cover'] : '' ?>" />
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">动态标题：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="title" value="<?=isset($timeline) ? $timeline['title'] : ''?>" placeholder="请填写动态标题"/>
				</div>
            </div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">所属栏目：</label>
				<div class="col-sm-6">
					<select class="chosen-select form-control tag-input-style" data-placeholder="选择栏目" name="subject_id">
						<?php foreach($subjectList as $subject): ?>
							<option value="<?=$subject['id']?>" <?= isset($timeline) && $subject['id'] == $timeline['subject_id'] ? 'selected' : '' ?>><?=$subject['title']?></option>
						<?php endforeach; ?>
					</select>
				</div>
			</div>
            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right">动态排序：</label>
                <div class="col-sm-6">
                    <input class="form-control" type="number" name="sort" value="<?= isset($timeline['sort']) ? $timeline['sort'] : 0 ?>" placeholder="请填写动态排序，根据序号从高往低排"/>
                </div>
            </div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">
					动态封面：
				</label>
				<div class="col-sm-6">
					<?php if(isset($timeline) && $timeline['cover']): ?>
						<a href="javascript:;" id="upload-img">
							<img class="fit-cover" src="<?=$timeline['cover']?>" />
						</a>
					<?php else: ?>
						<a href="javascript:;" id="upload-img">
							<img class="fit-cover" src="<?=$staticAdminUrl?>assets/images/upload.png" />
						</a>
					<?php endif; ?>
				</div>
			</div>
            <div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">动态内容：</label>
				<div class="col-sm-6">
					<textarea class="pd0" id="content" name="content" style="height: 300px;width: 100%"><?=isset($timeline) ? urldecode($timeline['content']) : ''?></textarea>
				</div>
            </div>
			<div class="clearfix">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn btn-info" type="submit">
						<i class="ace-icon fa fa-check"></i> 提交
					</button>
				</div>
			</div>
		</form>
	</div>
<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<!-- 百度编辑器 -->
<script src="<?=$staticAdminUrl?>assets/ueditor/ueditor.config.js"></script>
<script src="<?=$staticAdminUrl?>assets/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
	$(function(){
		// 上传图片对象
		$("#upload-img").uploader({
			"server":  '<?=UP_FORM_URL?>',
			"authorization": "<?=$signature?>",
			"policy": "<?=$policy?>",
			"callback": function(response) {
				var imgFile = "<?=UP_URL?>" + response.url;
				$("#upload-img").find("img").attr("src", imgFile);
				$("[name=cover]").val(imgFile);
			}
		});
		// 初始化编辑器
		var ue = UE.getEditor('content');
		// 提交表单
		var form = $("#timeline-form");
		var submitUrl = "<?=admin_url('moral/save_timeline_action')?>";
		form_submit(form, submitUrl, function(res) {
			tips_alert(res.msg, res.success, function(){
				if(res.success) {
					window.location.href = "<?=admin_url('moral/timeline')?>";
				}
			});
		})
	})
</script>